/**
* File Name: my_read.c
* Auther: Jichang
* Environment: Fedora 7 server
*/
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<string.h>
#include<errno.h>
#include<fcntl.h>
#include<sys/stat.h>
#include<event2/event.h>

void write_cb(evutil_socket_t fd, short what, void *arg) {
	char buf[] = "hello libevent";
	write(fd, buf, strlen(buf) + 1);

	sleep(1);
	return ;
}

int main(int argc, char *argv[])
{
	//打开fifo写端
	int fd = open("testfifo", O_WRONLY | O_NONBLOCK);
	if(fd == -1) {
		perror("open error");
		exit(1);
	}
	// 创建 event_base
	struct event_base *base = event_base_new();
	
	// 创建事件对象
	struct event *ev = NULL;
	ev = event_new(base, fd, EV_WRITE | EV_PERSIST, write_cb, NULL);
	// 添加事件
	event_add(ev, NULL);
	// 启动循环
	event_base_dispatch(base);  //while(1)
	// 销毁 event_base
	event_base_free(base);

	return 0;
}

